package daily;

import java.util.Arrays;
import java.util.Scanner;

public class MeiTuan05 {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p = sc.nextInt();
        int[] cost = new int[p+1];
        sc.nextLine();
        String s = sc.nextLine();
        for(int i = 1; i <= p; i++){
            cost[i] = sc.nextInt();
        }
        int len = s.length();
        int[] dp = new int[len];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for(int i = 1; i < len; i++){
            for(int k = 1; k <= p; k++){
                if(i-k>=0 && s.charAt(i-k)=='o'){
                    dp[i] = Math.min(dp[i], dp[i-k]+cost[k]);
                }
            }
        }
        System.out.println(dp[len-1]);
    }
}
